<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class MyinfoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
	//个人中心中个人信息的主页
    public function index()
    {
		$config = \DB::table("config")->get();
        $data = \DB::table("user")->where("id",session("homeuser")->id)->first();
		return view("home/personal/myinfo",["config"=>$config]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
	//修改密码中，验证密保是否正确
    public function create()
    {
		$question = $_GET['question'];
		$answer = $_GET['answer'];
		$data = \DB::table("user")->where("id",session("homeuser")->id)->first();
		if($data->question == $question && $data->answer == $answer){
			return "Y";
		}else{
			return "N";
		}
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
		//return "Y";
		//获取用户头像
		//使用自定义文件上传类处理上传
		$upfile = new \App\Org\Upload("photo");
		//初始化上传信息
		$upfile->path="./user/uploads"; //上传存储路径
		$upfile->typeList=array("image/jpeg","image/png","image/gif"); //设置允许上传类型
		$upfile->maxSize=0; //允许上传大小
		//执行文件上传
		$upfile->doUpload();
		$photo = $upfile->saveName;
		//进行数据库更新操作
		session("homeuser")->photo = $photo;
        \DB::table("user")->where("id",session("homeuser")->id)->update(["photo"=>$photo]);
		return $photo;
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
	//修改密码
    public function show($id)
    {
		$password = $_GET['password'];
		$password = md5($password);
		\DB::table("user")->where("id",session("homeuser")->id)->update(['password'=>$password]);
        return "Y";
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
